window.addEventListener( "load" , () => {
class Register{
    constructor(){
        // $(".myClass");
        $(".user-default-btn");
        this.bindevent()
        
        
    }
    bindevent(){
        $(".user-default-btn").on("click",()=>{
            this.register()
        })  
        $("#uname").on("focus",()=>{
            $("#PhoneInfo").css(
                "display","block",
        )
        })
        $("#uname").on("blur",()=>{
            $("#PhoneInfo").css(
                "display","none",
        )
        })
    }
    register(){
        var name_reg = /^[a-zA-Z0-9_-]{4,16}$/;
        var niname_reg = /^[a-zA-Z0-9_-]{4,16}$/;
        var pwd_reg=/^[0-9]*$/;
        var falg=0;
        if($("#uname").val().match(name_reg)){
            falg+=1;
        }else{
            return "用户名错误"
        }
        if($("#niname").val().match(niname_reg)){
            falg+=1;
        }else{
            return "昵称错误"
        }
        if($("#pwd").val().match(pwd_reg)){
            falg+=1;

        }else{
            return "密码格式错误"
        }
        if($("#pwd").val()===$("#password").val()){
            falg+=1;
        }else{
            return "与上面的密码不一致"
        }
        if(falg=4){
            this.succ()
        }else{
            this.err()
        }
        
    }
    succ(){
            localStorage.setItem(
                "uname",$("#uname").val()
            )
            localStorage.setItem("pwd",$("#pwd").val())
            location.href="../dist/login.html"
        }
    err(){
        console.log(2);
    }
}
new Register


})

